package com.hp.attendance.serlvet.history.OutGoing;

import com.hp.attendance.entity.History;
import com.hp.attendance.entity.HistoryBys;
import com.hp.attendance.entity.PageInfo;
import com.hp.attendance.service.HistoryBysService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/HistoryOutList")

public class HistoryListServlet extends HttpServlet {
    private HistoryBysService historyBysService = new HistoryBysService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
//            String status = req.getParameter("status");
//            List<History> hList = historyBysService.getHisListByStatus("离职");
//            req.setAttribute("hList",hList);
//
//            req.getRequestDispatcher("/pages/history_list_2.jsp").forward(req,resp);

            String pageNo = req.getParameter("pageNo");
            if(pageNo==null ||"".equals(pageNo.trim())){
                pageNo="1";
            }
            PageInfo<HistoryBys> page = historyBysService.getPageOut(Integer.parseInt(pageNo), 10);
            req.setAttribute("page",page);
            req.getRequestDispatcher("/pages/history_list.jsp").forward(req,resp);


        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
